/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beanControl;

import Utils.Helper;
import Utils.JDBCHelper;
import Utils.StringUtility;
import beanInfo.customers;
import java.util.ArrayList;
import javax.swing.JTable;

/**
 *
 * @author MiA
 */
public class customerControl {

    ArrayList<String> listColumn = new ArrayList<String>();
    ArrayList<String> listValue = new ArrayList<String>();
    customers cus = new customers();

    public void getlistCustomer(JTable table) {

        String sql = "select CusID,CusName,Gender,BirthDay,Identification,IssueDate,PlaceSupply,Status from Customers";
        String[] header = {"CusID", "CusName", "Gender", "BirthDay", "Identification", "IssueDate", "PlaceSupply","BranchesID", "Status"};
        Helper.loadDataTable(sql, table, header);

    }

    public void insertCustomer(customers cus) {
        Object[] values = {cus.getCusName(), cus.getGender(), cus.getBirthDay(), cus.getIdentification(),
            cus.getIssueDate(), cus.getPlaceSupply(), cus.getStatus(),cus.getBranchesID()};
        JDBCHelper.excuteInsertPlaceHolder("Customers", 8, values);
        Helper.successMessage("Insert  successfull", "wanning");

    }

    public void updateCustoner(customers cus) {
        String[] objColumn = {"CusName","Gender","BirthDay","Identification","IssueDate","PlaceSupply,Status"};
        String[] objValues = {cus.getCusName(), cus.getGender(), cus.getBirthDay(), cus.getIdentification(),
            cus.getIssueDate(), cus.getPlaceSupply(),String.valueOf(cus.getBranchesID()), cus.getStatus()};

        listColumn = (ArrayList<String>) StringUtility.ArrayToArrayList(objColumn);
        listValue = (ArrayList<String>) StringUtility.ArrayToArrayList(objValues);
        JDBCHelper.executeUpdate("Customers", listColumn, listValue, "UserName", String.valueOf(cus.getCusID()));
        Helper.successMessage("Update Sucessful", "furniture");
    }

    private int checkDelteCustomer(String values) {
        return JDBCHelper.excuteQueryReturnInt("CusID", "LoanProfile ", values);
    }

    public void Deletecus(customers cus) {
        if (checkDelteCustomer(String.valueOf(cus.getCusID())) > 0) {
            Helper.inforMessage("Can not detlete this User", "Wanning");
        } else {
            JDBCHelper.excuteDelete("Customers", "CusID", String.valueOf(cus.getCusID()));
            Helper.successMessage("Delete successfull", "wanning");
        }

    }
}
